class Solution {
public:

    int findSubstringInWraproundString(string s) {
        int n = s.size();
        vector<int> nums(26, 0);

        vector<int> dp(n + 1, 1);

        for (int i = 1; i <= n; i++)
        {
            if (s[i - 1] + 1 == s[i] || s[i - 1] == 'z' && s[i] == 'a')
                dp[i] += dp[i - 1];

            nums[s[i - 1] - 'a'] = max(dp[i], nums[s[i - 1] - 'a']);
        }
        int ret = 0;
        for (auto num : nums) ret += num;

        return ret;
    }
};